package com.sunfield.windpower.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sunfield.baseframe.base.MyRecyclerAdapter;
import com.sunfield.myglide.MyGlide;
import com.sunfield.windpower.R;
import com.sunfield.windpower.activity.WebViewActivity_;
import com.sunfield.windpower.bean.MessageInfo;

import org.androidannotations.annotations.EBean;

/**
 * Created by wxl on 2017/2/8.
 */
@EBean
public class MessageAdapter extends MyRecyclerAdapter<MessageInfo, MessageAdapter.ViewHolder> {
    public MessageAdapter(Context context) {
        super(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_message, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final MessageInfo data = getItem(position);
        MyGlide.with(context).load(R.drawable.news_icon_official).into(holder.iv_icon);
        holder.tv_title.setText(data.getTitle());
        holder.tv_time.setText(data.getDate());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebViewActivity_.intent(context).url(data.getUrl()).title("消息详情").start();
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public ImageView iv_icon;
        public TextView tv_title;
        public TextView tv_time;

        public ViewHolder(View rootView) {
            super(rootView);
            this.rootView = rootView;
            this.iv_icon = (ImageView) rootView.findViewById(R.id.iv_icon);
            this.tv_title = (TextView) rootView.findViewById(R.id.tv_title);
            this.tv_time = (TextView) rootView.findViewById(R.id.tv_time);
        }

    }
}
